/**     
* @Title: GroupServiceImpl.java
* @Package me.springboot.mybatis.service.impl 
* @Description: TODO
* @author zengh 
* @date 2018/04/19
* @version V1.0     
*/
package me.springboot.mybatis.service.impl;

import me.springboot.mybatis.core.RetCode;
import me.springboot.mybatis.dao.GroupMapper;
import me.springboot.mybatis.exception.ResultException;
import me.springboot.mybatis.model.Group;
import me.springboot.mybatis.service.GroupService;
import me.springboot.mybatis.core.AbstractService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**   
* @ClassName: GroupService   
* @Description: TODO
* @author zengh
* @date 2018/04/19
*/
@Service
@Transactional
public class GroupServiceImpl extends AbstractService<Group> implements GroupService {

    @Resource
    private GroupMapper groupMapper;

    @Override
    public void deleteGroup(Integer id) throws ResultException {
        Group group = groupMapper.selectByPrimaryKey(id);
        Group queryGroup = new Group();
        queryGroup.setParent(id);
        List<Group> groupChird = groupMapper.select(queryGroup);
        if(groupChird.size() > 0) {
            throw new ResultException(RetCode.BUS_FALL.getCode(), "存在子级分组不能删除");
        }

        groupMapper.delete(group);
    }

    @Override
    public void deleteGroupByIds(String ids) {
        String[] ss = ids.split(",");
        List<String> lists = new ArrayList<>();
        for(String s : ss) {
            lists.add(s);
        }
        groupMapper.deleteGroupByIds(lists);
    }
}